<template>
  <view class="custom-tabbar">
    <view
      v-for="(item, idx) in tabList"
      :key="item.pagePath"
      :class="['tabbar-item', { active: current === idx }]"
      @click="switchTab(idx, item.pagePath)"
    >
      <text class="tabbar-text">{{ item.text }}</text>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    current: { type: Number, default: 0 },
    tabList: { type: Array, default: () => [] }
  },
  methods: {
    switchTab(idx, pagePath) {
      if (this.current !== idx) {
        // 使用reLaunch确保页面重新加载
        uni.reLaunch({ url: '/' + pagePath });
      }
    }
  }
}
</script>

<style scoped>
.custom-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(25, 35, 60, 0.95); /* 深蓝灰色半透明背景 */
  backdrop-filter: blur(20rpx); /* 毛玻璃效果 */
  border-top: 1rpx solid rgba(255, 255, 255, 0.15);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  height: 56rpx;
  padding: 0 20rpx;
  padding-bottom: calc(0rpx + env(safe-area-inset-bottom));
  box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.3);
}

.tabbar-item {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  transition: all 0.3s ease;
  height: 100%;
  padding: 0 8rpx;
  border-radius: 8rpx;
}

.tabbar-text {
  font-size: 24rpx;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s ease;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  padding: 8rpx 12rpx;
  border-radius: 6rpx;
}

.tabbar-item.active {
  /* 移除所有背景效果 */
}

.tabbar-item.active .tabbar-text {
  color: #FFD700; /* 金色，更高级的视觉效果 */
  font-weight: 700;
  font-size: 30rpx;
  /* 移除背景颜色 */
  border-radius: 6rpx;
}

.tabbar-item:active {
  opacity: 0.8;
  transform: scale(0.98);
}

/* 优化选中状态的底部指示器 */
.tabbar-item.active::after {
  content: '';
  position: absolute;
  bottom: 0rpx;
  left: 50%;
  transform: translateX(-50%);
  width: 60rpx; /* 增加指示器宽度 */
  height: 3rpx;
  background: #FFD700; /* 金色指示器，与文字颜色一致 */
  border-radius: 2rpx;
  box-shadow: 0 1rpx 4rpx rgba(255, 215, 0, 0.6); /* 金色阴影 */
}

/* 响应式设计 */
@media (max-width: 750rpx) {
  .custom-tabbar {
    height: 40rpx; /* 降低高度 */
    padding: 0 16rpx;
  }
  
  .tabbar-text {
    font-size: 26rpx;
    padding: 6rpx 10rpx;
  }
}

/* 超小屏幕适配 */
@media (max-width: 600rpx) {
  .custom-tabbar {
    height: 36rpx; /* 降低高度 */
    padding: 0 12rpx;
  }
  
  .tabbar-text {
    font-size: 24rpx;
    padding: 5rpx 8rpx;
  }
}
</style> 